package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("nursing_project")
@Slf4j
@RequiredArgsConstructor
@Api(tags = "护理项目相关接口")
public class NursingProjectController extends BaseController {


    private final NursingProjectService nursingProjectService;


    /**
     * 分页查询
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ApiOperation("分页查询护理项目")
    @GetMapping
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
            @RequestParam(value = "name",required = false) String name,
            @RequestParam(value = "status",required = false) Integer status,
            @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize
    ){
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.getByPage(name,status,pageNum,pageSize);
        return success(pageResponse);

    }


    /**
     * 新增护理项目
     * @param nursingProjectDto
     * @return
     */
    @PostMapping
    public ResponseResult save(@RequestBody NursingProjectDto nursingProjectDto){
        log.info("新增");
        nursingProjectService.save(nursingProjectDto);
        return success();
    }


    /**
     * 根据id查询项目
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult<NursingProjectVo> getById(@PathVariable Long id){
        log.info("根据id查询护理项目:{}",id);
        NursingProjectVo vo = nursingProjectService.getById(id);
        return success(vo);
    }


    /**
     * 修改护理项目
     * @param nursingProjectDto
     * @return
     */
    @PutMapping()
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto){
        log.info("修改护理项目:{}",nursingProjectDto);
        nursingProjectService.update(nursingProjectDto);
        return success();
    }


    /**
     * 启用或禁用
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    public ResponseResult startOrStop(@PathVariable("id") Long id,@PathVariable("status") Integer status){
        log.info("启用或禁用");
        nursingProjectService.startOrStop(id,status);
        return success();
    }


    /**
     * 根据id删除护理项目
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseResult deleteById(@PathVariable Long id){
        log.info("根据id删除护理项目");
        nursingProjectService.deleteById(id);
        return success();
    }

}
